#!/usr/bin/env bash
DIR=`cd $(dirname "$0");pwd`
cd ${DIR}

docker pull spurin/hexo

mkdir -p data

docker create --name=hexo \
  -v $PWD/data:/app \
  -p 4000:4000 \
  spurin/hexo

docker start hexo

while true; do
    echo "waiting..."
    sleep 5
    curl "http://localhost:4000" | grep '<html>'
    [[ $? -eq 0 ]] && break
done

docker stop hexo

sudo chown -R $UID:$UID hexo

cp -r data blog.html
cd blog.html
git clone https://github.com/next-theme/hexo-theme-next themes/next

sed -i -e '/^theme/s/landscape/next/' _config.yml
rm -rf source/_posts
git clone https://gitee.com/hontlong/html.git source/_posts

docker create --name=hexo.html \
  -v $PWD/blog.html:/app \
  -p 4000:4000 \
  spurin/hexo

docker start hexo.html

cd ${DIR}
cp -r blog.html blog.xqrj
rm -rf blog.xqrj/source/_posts
git clone git@gitee.com:hontlong/xqrj.git blog.xqrj/source/_posts

docker create --name=hexo.xqrj \
  -v $PWD/blog.xqrj:/app \
  -p 4004:4000 \
  spurin/hexo

docker start hexo.xqrj

cd ${DIR}
cp -r blog.html blog.note
git clone https://github.com/yelog/hexo-theme-3-hexo.git blog.note/themes/3-hexo
sed -i -e '/^theme/s/next/3-hexo/' _config.yml
rm -rf blog.note/source/_posts
git clone https://gitee.com/hontlong/note.git blog.note/source/_posts

docker create --name=hexo.note \
  -v $PWD/blog.note:/app \
  -p 4002:4000 \
  spurin/hexo

docker start hexo.note

#mkdir -p blog.note
